package request;

import core.*;
import response.ResponseLocalPlayers;
import java.io.OutputStream;

import java.util.List;

/**
 * Gathers list of online players close to requesting player.
 *
 * @author brian
 */
public class RequestLocalPlayers extends GameRequest {

    // Values parsed from request.
    private String  username;      // Client's username.
    private Short   constraint,	   // What to return, see constants below.
                    screen_width,  // Width of display.
                    screen_height; // Height of display.

    private final short ONSCREEN=0, ONMAP=1, ONGPS=0;  // constraint enumeration

    // Values used in processing and response
    private float pos_x, pos_y;
    /*Comment out for testing
    Vector<PlayerCoords> local_players;
     */

    public RequestLocalPlayers() {
        code = Constants.CMSG_LOCAL_PLAYERS;
    }

    public void parse() {
        // protocol := username, constraint, screen_width, screen_height
        gameServer.log("Server: ... parsing request ", "d");
        /*Comment out for testing
        user = client.getUser();
        character = gameServer.selectCharacter(user.getID(), 0);
        map = gameServer.getMap(character.getMapID());
        */
        username = client.readString(dataIn);
        constraint = client.readShort(dataIn);
        screen_width = client.readShort(dataIn);
        screen_height = client.readShort(dataIn);

        gameServer.log("RequestLocalPlayers: " + username + " " + constraint + " " + screen_width + " " + screen_height, "d");
        /* */

        /*Comment out for testing
        if(constraint == ONSCREEN) {
            // Get local player's x and y position.
            pos_x = character.getX();
            pos_y = character.getY();
            local_players = gameServer.getLocalPlayers(map,pos_x,pos_y);
        }
        else
            local_players = gameServer.getLocalPlayers(map);
         *
         */
    }

    public void respond(OutputStream output) {
        ResponseLocalPlayers response = new ResponseLocalPlayers();
        response.set(gameServer);
        response.setOut(output);
        response.run();

    }
}